package cms.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * 功能: 设置HTTP通信编码
 * Author: yuhui
 * Date: 2021/4/8 17:39
 */
public class HttpCharSet {

    /**
    * 功能描述: 设置请求/响应/浏览器解析 的编码 UTF-8
    * @Author: yuhui  2021/4/8 17:42
    */
    public static void charSet(HttpServletRequest req, HttpServletResponse resp){
        try {
            req.setCharacterEncoding("UTF-8");
            resp.setCharacterEncoding("UTF-8");
            resp.setContentType("text/json;charset=utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
